import Mock from "mockjs";
import payEntity from "../model/pay.entity";

const payInstance = new payEntity();


// 支付列表
Mock.mock(RegExp('/mock/api/pay/list' + '.*'), 'get', (options) => {
  return Mock.mock({
    code: 200,
    msg: 'success',
    data: payInstance.findAll(),
  })
})

// 微信支付配置详情
Mock.mock(RegExp('/mock/api/wechat_pay/configInfo' + '.*'), 'get', (options) => {
  return Mock.mock({
    code: 200,
    msg: 'success',
    data: payInstance.findAll().find((x:any) => x.pay_type === 'wxpay'),
  })
})

// 微信支付设置
Mock.mock(
  RegExp("/api/wechat_pay/config" + ".*"),
  "post",
  (response: any) => {
    let res = JSON.parse(response.body);
    payInstance.update('wxpay', res);
    return Mock.mock({
      code: 200,
      msg: "success",
      data: {},
    });
  }
);